package br.edu.utfpr.md.tads.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import br.edu.utfpr.md.tads.R;

public class CallDialog extends Dialog implements android.view.View.OnClickListener {
	private Activity activity;
	private EditText editTextNumber;
	private Button  buttonChamar;
	private Button  buttonFechar;
	
	public CallDialog(Context context,Activity activity,String number) {
		super(context);
		setContentView(R.layout.dialog_edit_number);
		this.activity = activity;
		
		String n = number.replace("(", "");
		n = n.replace(")", "");
		n = n.replace("-", "");
		n = n.replace(" ", "");
		editTextNumber = (EditText) findViewById(R.dialog_edit_number.edit_text_numero);
		editTextNumber.setText(n);
		buttonChamar = (Button) findViewById(R.dialog_edit_number.button_ligar);
		buttonFechar = (Button) findViewById(R.dialog_edit_number.button_fechar);
		
		buttonChamar.setOnClickListener(this);
		buttonFechar.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.dialog_edit_number.button_fechar:
			dismiss();
			break;
		case R.dialog_edit_number.button_ligar:
			ligar();
			dismiss();
			break;
		default:
			break;
		}
		
	}

	private void ligar() {
		Intent dial = new Intent(android.content.Intent.ACTION_CALL,Uri.parse("tel:"+editTextNumber.getText().toString().trim()));
		activity.startActivity(Intent.createChooser(dial,"Chamando... "));
		
	}

}
